package com.show.dao.sys_emp;


import com.show.dto.sys_emp.SysEmp;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

/**
 * 用户jpa接口
 *
 * @author baiyu
 * @Param
 * @date 2018-01-29
 */
public interface EmpRepository extends JpaRepository<SysEmp, String>, JpaSpecificationExecutor<SysEmp> {

    @Query(value = "SELECT * FROM sys_emp ee WHERE ee.login_name = ? and ee.login_pwd = ?" ,nativeQuery = true)
    SysEmp getEmp(String loginName, String loginPwd);

    @Query(value = "SELECT * FROM sys_emp e WHERE e.login_name = ?",nativeQuery = true)
    SysEmp findUserInfoByName(String empLogin);

    @Query(value = "SELECT * FROM sys_emp e WHERE e.emp_id = ?",nativeQuery = true)
    SysEmp findOneById(int empId);

    @Modifying
    @Query(value = "update sys_emp set sts='0' where emp_id=?",nativeQuery = true)
    void deleteEmp(int emp_id);

    @Modifying
    @Query(value = "update sys_emp set sts='1' where emp_id=?",nativeQuery = true)
    void reply(int emp_id);

    @Modifying
    @Query(value = "update sys_emp set login_pwd=? where emp_id=?",nativeQuery = true)
    void replyPwd(String loginPwd, int emp_id);


    @Modifying
    @Query(value = "UPDATE sys_emp SET login_pwd = ? WHERE login_name = ?",nativeQuery = true)
    int updatePwd(String pwd, String loginName);
}